<template>
	<view class="login">
		<image class="bg" src="../../static/image/loginBg.png" mode="widthFix"></image>
		<view class="tool">
			<view class="loginBtn" @click="login">授权登录</view>
			<view class="agreement">
				<u-checkbox active-color="#f05948" @change="checkboxChange"></u-checkbox>
				<view class="agreement-text">
					我已阅读并同意<text @click="toAgreement('service')">《用户服务协议》</text>和<text
						@click="toAgreement('privacy')">《隐私政策条款》</text>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		post
	} from '../../static/utils/request';
	import {
		Login
	} from '../../static/utils/service';
	import {
		Loading,
		Routes,
		Toast,
		WxBaseApi
	} from '../../static/utils/utils';
	import {
		mapMutations
	} from 'vuex'
	export default {
		data() {
			return {
				isAgreement: false
			}
		},
		methods: {
			...mapMutations(['setLogin']),
			checkboxChange(e) {
				this.isAgreement = e
			},
			async login() {
				if (!this.isAgreement) {
					Toast.error('请同意协议')
					return
				}
				Loading.show('登录中')
				const wxCode = await WxBaseApi.getCode()
				const loginRes = await post(Login.mnpLogin, {
					code: wxCode
				})
				Loading.hidden()
				if (loginRes.code === 1) {
					this.setLogin(loginRes.data)
					Routes.tab('/pages/index/index')
				} else Toast.none(loginRes.msg)
			},
			toAgreement(type) {
				Routes.push(`/pages/agreement/agreement?type=${type}`)
			}
		}
	}
</script>

<style lang="scss">
	page {
		background-color: #fffcf5;
	}

	.bg {
		position: fixed;
		top: 0;
		left: 0;
		width: 100vw;
	}

	.tool {
		position: fixed;
		bottom: 60rpx;
		left: 50%;
		transform: translateX(-50%);
		width: 85vw;

		.loginBtn {
			height: 80rpx;
			border-radius: 80rpx;
			background-color: #f05948;
			text-align: center;
			line-height: 80rpx;
			color: #fff;
		}

		.agreement {
			margin-top: 50rpx;
			display: flex;
			align-items: flex-start;

			.agreement-text {
				font-size: 24rpx;
				color: #9b9daa;

				text {
					color: #f05948;
				}
			}
		}
	}
</style>